<%@ page import="com.surelution.projects.crm.OwnStation" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:javascript library="jquery" plugin="jquery"/>
        <g:set var="entityName" value="${message(code: 'market.label', default: 'market')}" />
        <title><g:message code="default.reset.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
        </div>
        <div class="body">
            <h1><g:message code="default.reset.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:hasErrors bean="${marketInstance}">
            <div class="errors">
                <g:renderErrors bean="${marketInstance}" as="list" />
            </div>
            </g:hasErrors>
            <g:form method="post" >
                <g:hiddenField name="version" value="${marketInstance?.version}" />
                <div class="dialog">
                    <table>
                        <tbody>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="name">请选择客户名称</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: marketInstance, field: 'name', 'errors')}">
                                    <g:select name="id" from="${marketList}" optionKey="id" optionValue="name" value="${marketInstance?.name}"  />
                                </td>

                            </tr>   
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="latitude"><g:message code="market.latitude.label" default="Latitude" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: marketInstance, field: 'latitude', 'errors')}">
                                    <g:textField name="latitude" id="lat" value="${marketInstance?.latitude}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="longitude"><g:message code="market.longitude.label" default="Longitude" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: marketInstance, field: 'longitude', 'errors')}">
                                    <g:textField name="longitude" id="lng" value="${marketInstance?.longitude}" />
                                </td>
                            </tr>
                        
                        </tbody>
                    </table>
                </div>
                <div class="buttons">
                    <span class="button"><g:actionSubmit class="save" action="resetPosition" value="${message(code: 'default.button.update.label', default: 'Update')}" /></span>
                </div>
            </g:form>
        <div style="height:50px;"></div>
		<div class="left_body">
			<label style="color:blue;font-size:16px;padding:5px 0px;">拖动红色小气球，可微调坐标</label>
			<div id="SmallMap"></div>
		</div>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
		<script type="text/javascript">
			var map;
			function initMap() {

				var lat=30.748013;
				var lng=120.741578;
				var type="BMAP_HYBRID_MAP";
				var zoom=13;
				var url=location.search;
				if(url.indexOf("?")!=-1)   
				{   
				  var str = url.substr(1);
				  strs = str.split("&");   
				  for(i=0;i<strs.length;i++)   
				  {   
				    if([strs[i].split("=")[0]]=='lat') lat=unescape(strs[i].split("=")[1]);
				    if([strs[i].split("=")[0]]=='lng') lng=unescape(strs[i].split("=")[1]);
				    if([strs[i].split("=")[0]]=='zoom') zoom=unescape(strs[i].split("=")[1]);
				    if([strs[i].split("=")[0]]=='mapType') type=unescape(strs[i].split("=")[1]);
				  }   
				}
				map = new BMap.Map("SmallMap");
				if (type == "BMAP_NORMAL_MAP"){
					map.setMapType(BMAP_NORMAL_MAP);
					}
				if (type == "BMAP_SATELLITE_MAP"){
					map.setMapType(BMAP_SATELLITE_MAP);
					}
				if (type == "BMAP_HYBRID_MAP"){
					map.setMapType(BMAP_HYBRID_MAP);
					}
				var center = new BMap.Point(lng, lat);
				map.centerAndZoom(center, zoom);
				map.addControl(new BMap.NavigationControl());
				map.addControl(new BMap.MapTypeControl({mapTypes:[BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP]}));
				addMarker(lng,lat);
				
			}			

			function addMarker(x, y){
				var myIcon = new BMap.Icon(
						"http://api.map.baidu.com/img/markers.png" , 
						new BMap.Size(23, 25), 
						{offset: new BMap.Size(32, 32),size:new BMap.Size(23, 25)}
				);
				var point = new BMap.Point(x, y);
				var marker = new BMap.Marker(point, {icon: myIcon}); 
				marker.enableDragging(true);
				marker.addEventListener("dragend", function(e){
					var lng = e.point.lng;
					var lat = e.point.lat;
					document.getElementById("lat").value=lat;  
					document.getElementById("lng").value=lng;  
				});
				map.addOverlay(marker);
			}
			
			$(document).ready(function() {
				initMap();
			 });
			</script>	


        </div>
    </body>
</html>